package com.wushijia.highconcurrency.threadlocal;

import java.lang.ref.WeakReference;

public class ThreadLocalDemo02 {

  /**
   * description:gc不清理常量池里的垃圾，所以所引用的内容不为null
   *
   * @author yang
   * @date 2019/9/3 11:49
   */
  public static void main(String[] args) {
    String str = "hello world";
    Object object = new Object();
    ThreadLocal threadLocal = new ThreadLocal();
    WeakReference<Object> weakReference = new WeakReference<Object>(object);
    WeakReference<Object> weakReferenceStr = new WeakReference<Object>(str);
    object = null;
    str = null;
    System.gc();
    System.out.println("after system.gc---weakReference = " + weakReference.get());
    System.out.print("after system.gc---weakReferenceStr = " + weakReferenceStr.get());
  }
}
